//
//  SEWeatherDTO.m
//  kuaiyi
//
//  Created by Alphts on 16/7/6.
//  Copyright © 2016年 Alphts. All rights reserved.
//

#import "SEWeatherDTO.h"

@implementation SEWeatherDTO

+ (instancetype)weatherModelWithDictionary:(NSDictionary *)dict{
    
    SEWeatherDTO *model = [[self alloc] init];
    
    [model setValuesForKeysWithDictionary:dict];
    
    return model;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{}


+ (void)modelWithCityName:(NSString *)cityName successBlock:(void (^)(SEWeatherDTO *))successBlock errorBlock:(void (^)())errorBlock{
    
    NSString *url = @"http://api.map.baidu.com/telematics/v3/weather";
    
    NSDictionary *paramDic = @{@"location":cityName,
                               @"output":@"json",
                               @"ak":@"17IvzuqmKrK1cGwNL6VQebF9"
                               };
    
    [[NetworkTool shareManager] GET:url parameters:paramDic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        
        NSArray *resultArray = responseObject[@"results"];
        
        NSDictionary *tempDict = resultArray.firstObject;
        
        NSArray *tempArray = tempDict[@"weather_data"];
        
        NSDictionary *dict = tempArray.firstObject;
        
        SEWeatherDTO *model = [SEWeatherDTO weatherModelWithDictionary:dict];
        
        if (successBlock) {
            successBlock(model);
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       
        if (errorBlock) {
            errorBlock();
        }
    }];
}

- (NSString *)trueData{
    
    
    //截取字符串
    NSRange range = [_date rangeOfString:@"("];
    
    return [_date substringToIndex:range.location];
}




@end











